package robot.utils;

public class Convertions {
	static private final int mask = 0x000000FF;

	public Convertions () {

	}

	static public byte[] toByteTab (long n) {
		byte [] r = {0x00, 0x00, 0x00, 0x00};

		r[0] = (byte) (n & mask);  
		r[1] = (byte) ((n >> 8) & mask);
		r[2] = (byte) ((n >> 16) & mask);
		r[3] = (byte) ((n >> 24) & mask);

		return r;
	}

	static public byte[] toByteTab (int n) {
		byte [] r = {0x00, 0x00};

		r[0] = (byte) (n & mask);  
		r[1] = (byte) ((n >> 8) & mask);

		return r;
	}

	static public long toLong (byte[] r) {
		return (r[0] & mask) +
		((r[1] & mask) << 8) +
		((r[2] & mask) << 16) +
		((r[3] & mask) << 24);
	}

	static public int toInt (byte[] r) {
		return (r[0] & mask) +
		((r[1] & mask) << 8);
	}
}
